<!-- 子账号管理 -->
<template>
  <div class="app-container">
    
    <div class="juese-box">
      <div style="margin-bottom: 5px;">
        <subtit title="岗位管理"></subtit>
      </div>
      <el-form class="search-form-new" :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true">
        <el-form-item label="店铺" prop="tenantId" v-hasPermi="['searchTenantID']">
          <el-select
            v-model="queryParams.tenantId"
            placeholder="请选择店铺"
            clearable
            filterable
          >
            <el-option
              v-for="dict in tenantList"
              :key="dict.tenantId"
              :label="dict.tenantName"
              :value="dict.tenantId"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="角色名称" prop="roleName">
          <el-input
            v-model="queryParams.roleName"
            placeholder="请输入角色名称"
            clearable
          />
        </el-form-item>
        <!-- <el-form-item label="权限字符" prop="roleKey">
          <el-input
            v-model="queryParams.roleKey"
            placeholder="请输入权限字符"
            clearable
          />
        </el-form-item> -->
        <el-form-item label="角色状态" prop="status">
          <el-select
            v-model="queryParams.status"
            placeholder="请选择角色状态"
            clearable
          >
            <el-option
              v-for="dict in dict.type.sys_normal_disable"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="创建时间">
          <el-date-picker
            v-model="dateRange"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
        </el-form-item>
        <el-form-item class="btns">
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
          <el-button type="warning" icon="el-icon-refresh" @click="resetQuery">重置</el-button>
          <el-button
            type="success"
            icon="el-icon-plus"
            @click="handleAdd"
            v-hasPermi="['system:role:add']"
          >新增</el-button>
       
        </el-form-item>
      </el-form>

    
      <div class="table_box">
        <el-table stripe v-loading="loading" :data="roleList">
          <el-table-column type="selection" width="55"  />
          <el-table-column label="角色编号" prop="roleId" width="120" />
          <el-table-column label="角色名称" prop="roleName" :show-overflow-tooltip="true"  />
          <!-- <el-table-column label="权限字符" prop="roleKey" :show-overflow-tooltip="true" /> -->
          <el-table-column label="显示顺序" prop="roleSort" width="100" />
          <el-table-column label="状态"  width="100">
            <template slot-scope="scope">
              <el-switch
                v-model="scope.row.status"
                active-value="0"
                inactive-value="1"
                @change="handleStatusChange(scope.row)"
              ></el-switch>
            </template>
          </el-table-column>
          <el-table-column label="创建时间"  prop="createTime" width="200">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作"  class-name="small-padding fixed-width">
            <template slot-scope="scope" v-if="scope.row.roleId !== 1">
              <el-button
                type="edit"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['system:role:edit']"
              >修改</el-button>
              <el-button
                type="del"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-if="!(scope.row.roleKey&&scope.row.roleKey.includes('shop_admin'))&&checkPermi(['system:role:remove'])"
              >删除</el-button>
             
            </template>
          </el-table-column>
        </el-table>

        <pagination
          :layout="'total,  prev, pager, next, jumper'"
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </div>
    </div>
    
    <!-- 客服管理 -->
    <div class="kefu-box">
      <!-- <div style="font-size: 15px;font-weight: bold;margin-bottom: 10px;">
        在线客服
      </div> -->
      <customerService ref="customerService"></customerService>


    </div>
    
    

    <!-- 添加或修改角色配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="110px" v-loading="btnLoading">
        <el-form-item label="角色名称:" prop="roleName">
          <el-input v-model="form.roleName" placeholder="请输入角色名称" style="width: 200px;"/>
        </el-form-item>
        <!-- <el-form-item prop="roleKey">
          <span slot="label">
            <el-tooltip content="控制器中定义的权限字符，如：@PreAuthorize(`@ss.hasRole('admin')`)" placement="top">
              <i class="el-icon-question"></i>
            </el-tooltip>
            权限字符:
          </span>
          <el-input v-model="form.roleKey" placeholder="请输入权限字符" />
        </el-form-item> -->
        <el-form-item label="角色顺序:" prop="roleSort">
          <el-input-number v-model="form.roleSort" controls-position="right" :min="0" />
        </el-form-item>
        <el-form-item label="状态:">
          <el-radio-group v-model="form.status">
            <el-radio
              v-for="dict in dict.type.sys_normal_disable"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <!-- <el-form-item label="权限">
          <el-checkbox v-model="menuExpand" @change="handleCheckedTreeExpand($event, 'menu')">展开/折叠</el-checkbox>
          
          <el-tree
            class="tree-border"
            :data="menuOptions"
            show-checkbox
            ref="menu"
            node-key="id"
            :check-strictly="!form.menuCheckStrictly"
            empty-text="加载中，请稍候"
            :props="defaultProps"
          ></el-tree>
          
        </el-form-item> -->
        <div style="font-size: 15px;font-weight: bold;width: 100px;margin-bottom: 10px;">
          角色权限:
        </div>
        <div style="border: 1px solid #e2e2e2;padding: 0 10px 10px;border-radius: 4px;padding-top: 15px;margin-bottom: 20px;">
          
            <el-tabs v-model="activeName" @tab-click="handleClick">
              <el-tab-pane label="角色成员" name="juese">
                <div class="table_box">
                  <el-table border @row-click="clickRow" ref="usertable" :data="userList" @selection-change="handleSelectionChange" >
                    <el-table-column type="selection" width="55"></el-table-column>
                    <el-table-column label="昵称" prop="nickName" :show-overflow-tooltip="true" />
                    <el-table-column label="登录账号" prop="userName" :show-overflow-tooltip="true" />
                    <el-table-column label="手机" prop="phonenumber" :show-overflow-tooltip="true" />
                    
                    <el-table-column label="创建时间" align="center" prop="createTime" width="180">
                      <template slot-scope="scope">
                        <span>{{ parseTime(scope.row.createTime) }}</span>
                      </template>
                    </el-table-column>
                    <el-table-column label="状态" align="center" prop="status">
                      <template slot-scope="scope">
                        <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/>
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
              </el-tab-pane>
              <el-tab-pane label="功能权限" name="gongneng">
                <div style="margin-bottom:10px">
                  <el-checkbox :disabled="form.roleKey&&form.roleKey.includes('shop_admin')" v-model="menuNodeAll" @change="handleCheckedTreeNodeAll($event, 'menu')">全选/全不选</el-checkbox>
                  <el-checkbox :disabled="form.roleKey&&form.roleKey.includes('shop_admin')" v-model="form.menuCheckStrictly" @change="handleCheckedTreeConnect($event, 'menu')">父子联动</el-checkbox>
                </div>
                <div class="tableheader flex">
                  <div style="width: 150px;flex-shrink: 0;text-align: center">
                    模块
                  </div>
                  <div style="width: 150px;flex-shrink: 0;text-align: center">
                    功能
                  </div>
                  <div style="width: 100%;text-align: center">
                    操作权限
                  </div>

                </div>
                <div class="gongneng-box" v-if="menuOptions&&menuOptions.length">
                  <el-checkbox-group v-model="checkList1" :disabled="form.roleKey&&form.roleKey.includes('shop_admin')">
                    <template v-for="menu1 in menuOptions" >
                      <div class="yiji flex" >
                        <div class="name-box">
                          <el-checkbox @change="menuCheckChange($event,menu1)" :label="menu1.id" >{{ menu1.label }}</el-checkbox>
                        </div>
                        <div v-if="menu1.children&&menu1.children.length" class="erji-box">
                          <template v-for="menu2 in menu1.children">
                            <div class="erji flex">
                              <div class="name-box">
                                <el-checkbox @change="menuCheckChange($event,menu2)" :label="menu2.id" >{{ menu2.label }}</el-checkbox>
                              </div>
                              <div v-if="menu2.children&&menu2.children.length" class="sanji-box flex">
                                <template v-for="menu3 in menu2.children">
                                  <span class="sanji">
                                    <el-checkbox :label="menu3.id" >{{ menu3.label }}</el-checkbox>
                                  </span>
                                </template>
                              </div>
                            </div>
                          </template>
                        </div>
                      </div>
                    </template>

                  </el-checkbox-group>
                  
                </div>
              </el-tab-pane>
              <el-tab-pane label="数据范围" name="shuju">
                <div style="padding: 15px;border:1px solid #E2E2E2;border-radius:4px;">
                  <el-radio-group v-model="form.dataScope" @change="dataScopeSelectChange" :disabled="form.roleKey&&form.roleKey.includes('shop_admin')">
                    <el-radio v-for="item in dataScopeOptions" :key="item.value"  :label="item.value" >{{ item.label }}</el-radio>
                    
                  </el-radio-group>
                  <div v-show="form.dataScope==2" style="margin-top:15px; padding:10px;border:1px solid #E2E2E2;border-radius:4px;">
                    <!-- <el-checkbox v-model="deptExpand" @change="handleCheckedTreeExpand($event, 'dept')">展开/折叠</el-checkbox> -->
                    <el-checkbox v-model="deptNodeAll" @change="handleCheckedTreeNodeAll($event, 'dept')">全选/全不选</el-checkbox>
                    <el-checkbox v-model="form.deptCheckStrictly" @change="handleCheckedTreeConnect($event, 'dept')">父子联动</el-checkbox>
                    <div style="height:10px"></div>
                    <el-tree
                      class="tree-border"
                      :data="deptOptions"
                      show-checkbox
                      default-expand-all
                      ref="dept"
                      node-key="id"
                      :check-strictly="!form.deptCheckStrictly"
                      empty-text="加载中，请稍候"
                      :props="defaultProps"
                    ></el-tree>
                    
                  </div>
                </div>
              </el-tab-pane>
            </el-tabs>
          </div>

        <!-- 

        -->
        
        <!-- <el-form-item label="备注">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button :loading="btnLoading" type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>


  </div>
</template>

<script>
import { listRole, getRole, delRole, addRole, updateRole, exportRole, dataScope, changeRoleStatus,allocatedUserList2 ,authUserSelectAll2} from "@/api/system/role";
import { treeselect as menuTreeselect, roleMenuTreeselect } from "@/api/system/menu";
import { treeselect as deptTreeselect, roleDeptTreeselect } from "@/api/system/dept";
import supplyConfigApi from "@/api/system/supplyConfig"
import customerService from "./customerService.vue"
import { pinyin } from 'pinyin-pro';
import subtit from "@/components/indexComponents/subtit.vue";
export default {
  name: "Juese2",
  dicts: ['sys_normal_disable'],
  components:{customerService,subtit},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 角色表格数据
      roleList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示弹出层（数据权限）
      openDataScope: false,
      menuExpand: false,
      menuNodeAll: false,
      deptExpand: true,
      deptNodeAll: false,
      // 日期范围
      dateRange: [],
      // 数据范围选项
      dataScopeOptions: [
        {
          value: "1",
          label: "全部数据权限"
        },
        {
          value: "2",
          label: "自定数据权限"
        },
        {
          value: "3",
          label: "本部门数据权限"
        },
        {
          value: "4",
          label: "本部门及以下数据权限"
        },
        {
          value: "5",
          label: "仅本人数据权限"
        }
      ],
      // 菜单列表
      menuOptions: [],
      // 部门列表
      deptOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 4,
        roleName: undefined,
        roleKey: undefined,
        status: undefined,
        tenantId:undefined
      },
      // 表单参数
      form: {},
      defaultProps: {
        children: "children",
        label: "label"
      },
      // 表单校验
      rules: {
        roleName: [
          { required: true, message: "角色名称不能为空", trigger: "blur" }
        ],
        // roleKey: [
        //   { required: true, message: "权限字符不能为空", trigger: "blur" }
        // ],
        roleSort: [
          { required: true, message: "角色顺序不能为空", trigger: "blur" }
        ]
      },

      // 弹出框需要的参数
      activeName:'gongneng',
      checkList1:[],//所有选中菜单的ids

      userList:[],//成员用户列表
      userIds:[],//选择的用户ids
      innerUserList:[],//选择的用户
      btnLoading:false
      
    };
  },
  created() {
    this.getList();
  },
  computed: {
    tenantList() {
      return this.$store.getters.tenantList
    },
    userInfo() {
      return this.$store.getters.userInfo;
    },
    shopInfo() {
      return this.$store.getters.shopInfo;
    },
  
  },
  methods: {

    //弹出框切换tab handleClick
    handleClick(e){
      if(e.name=='juese'){
        if(this.userList.length==0){
          this.getUserList()
        }
      }

    },
    // 查询所有用户列表
    getUserList() {
      this.btnLoading = true
      supplyConfigApi.getAllUserList({
        userNewType:1
      }).then(res => {
        this.userList = res.rows
        this.getInnerUserList()
      })
    },


    // 查询已选成员列表
    getInnerUserList() {
      allocatedUserList2({
        roleId:this.form.roleId
      }).then(res => {
        this.innerUserList = res.rows
        this.userTableCheck()
        this.btnLoading = false
      });
    },
    //回显已选择用户
    userTableCheck(){
      if(this.userList.length&&this.innerUserList.length){
        this.$refs.usertable.clearSelection()
        this.$nextTick(()=>{
          this.userList.forEach(r=>{
            this.innerUserList.forEach(r2=>{
              if(r.userId==r2.userId){
                this.$refs.usertable.toggleRowSelection(r)
              }
            })
          })
        })
      }
    },
    // 保存选择的成员
    /** 选择授权用户操作 */
    async saveSelectUser() {
      const roleId = this.form.roleId;
      const userIds = this.userIds.join(",");
      await authUserSelectAll2({ roleId: roleId, userIds: userIds })
    },




    /** 查询角色列表 */
    getList() {
      this.loading = true;
      listRole(this.addDateRange(this.queryParams, this.dateRange)).then(
        response => {
          this.roleList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    /** 查询菜单树结构 */
    getMenuTreeselect() {
      this.btnLoading = true
      menuTreeselect().then(response => {
        this.menuOptions = response.data;
        this.btnLoading = false
      });
    },
    /** 查询部门树结构 */
    getDeptTreeselect() {
      deptTreeselect().then(response => {
        this.deptOptions = response.data;
      });
    },
    // 所有菜单节点数据
    getMenuAllCheckedKeys() {
      // 目前被选中的菜单节点
      let checkedKeys = this.$refs.menu.getCheckedKeys();
      // 半选中的菜单节点
      let halfCheckedKeys = this.$refs.menu.getHalfCheckedKeys();
      checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys);
      return checkedKeys;
    },
    // 所有部门节点数据
    getDeptAllCheckedKeys() {
      // 目前被选中的部门节点
      let checkedKeys = this.$refs.dept.getCheckedKeys();
      // 半选中的部门节点
      let halfCheckedKeys = this.$refs.dept.getHalfCheckedKeys();
      checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys);
      return checkedKeys;
    },
    /** 根据角色ID查询菜单树结构 */
    getRoleMenuTreeselect(roleId) {
      return roleMenuTreeselect(roleId).then(response => {
        this.menuOptions = response.menus;
        return response;
      });
    },
    /** 根据角色ID查询部门树结构 */
    getRoleDeptTreeselect(roleId) {
      return roleDeptTreeselect(roleId).then(response => {
        this.deptOptions = response.depts;
        return response;
      });
    },
    // 角色状态修改
    handleStatusChange(row) {
      let text = row.status === "0" ? "启用" : "停用";
      this.$modal.confirm('确认要"' + text + '""' + row.roleName + '"角色吗？').then(function() {
        return changeRoleStatus(row.roleId, row.status);
      }).then(() => {
        this.$modal.msgSuccess(text + "成功");
      }).catch(function() {
        row.status = row.status === "0" ? "1" : "0";
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 取消按钮（数据权限）
    cancelDataScope() {
      this.openDataScope = false;
      this.reset();
    },
    // 表单重置
    reset() {
      if (this.$refs.menu != undefined) {
        this.$refs.menu.setCheckedKeys([]);
      }
      if (this.$refs.dept != undefined) {
        this.$refs.dept.setCheckedKeys([]);
      }
      this.activeName ='gongneng'
      this.deptOptions = []
      this.userList = []
      this.innerUserList = []
      this.userIds = []
      this.checkList1 = []
      this.menuExpand = false,
      this.menuNodeAll = false,
      this.deptExpand = true,
      this.deptNodeAll = false,
      this.form = {
        roleId: undefined,
        roleName: undefined,
        roleKey: undefined,
        roleSort: 0,
        status: "0",
        menuIds: [],
        deptIds: [],
        menuCheckStrictly: true,
        deptCheckStrictly: true,
        remark: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      // this.ids = selection.map(item => item.roleId)
      // this.single = selection.length!=1
      // this.multiple = !selection.length
      this.userIds = selection.map(item => item.userId);
    },
    // 点击用户列表 行
    clickRow(row) {
      this.$refs.usertable.toggleRowSelection(row);
    },
    // // 更多操作触发
    // handleCommand(command, row) {
    //   switch (command) {
    //     case "handleDataScope":
    //       this.handleDataScope(row);
    //       break;
    //     case "handleAuthUser":
    //       this.handleAuthUser(row);
    //       break;
    //     default:
    //       break;
    //   }
    // },
    // 树权限（展开/折叠）
    handleCheckedTreeExpand(value, type) {
      if (type == 'menu') {
        let treeList = this.menuOptions;
        for (let i = 0; i < treeList.length; i++) {
          this.$refs.menu.store.nodesMap[treeList[i].id].expanded = value;
        }
      } else if (type == 'dept') {
        let treeList = this.deptOptions;
        for (let i = 0; i < treeList.length; i++) {
          this.$refs.dept.store.nodesMap[treeList[i].id].expanded = value;
        }
      }
    },
    // 菜单选择改变  实现父子联动
    menuCheckChange(e,menu){
        if(this.form.menuCheckStrictly&&menu.children){
          // if(e){
          //   const i = this.checkList1.indexOf(menu.id)
          //   if(i>0) this.checkList1.splice(i,1)
          //   this.checkList1.unshift(menu.id)

          // }
          menu.children.forEach(m1=>{
                    if(e){
                      if(!this.checkList1.includes(m1.id)) this.checkList1.push(m1.id)
                    }else{
                      const i = this.checkList1.indexOf(m1.id)
                      if(i>-1) this.checkList1.splice(i,1)
                    }
                if(m1.children){
                  m1.children.forEach(m2=>{
                    if(e){
                      if(!this.checkList1.includes(m2.id)) this.checkList1.push(m2.id)
                    }else{
                      const i = this.checkList1.indexOf(m2.id)
                      if(i>-1) this.checkList1.splice(i,1)
                    }
                    
                    if(m2.children){
                      m2.children.forEach(m3=>{
                        if(e){
                          if(!this.checkList1.includes(m3.id)) this.checkList1.push(m3.id)
                        }else{
                          const i = this.checkList1.indexOf(m3.id)
                          if(i>-1) this.checkList1.splice(i,1)
                        }
                      
                      })
                    }
                  })
                }
              
            })

        }
     
      
    },
    // 树权限（全选/全不选）
    handleCheckedTreeNodeAll(value, type) {
      if(this.activeName=='gongneng'){
        if(value){
          // 全选
          this.menuOptions.forEach(m1=>{
            if(!this.checkList1.includes(m1.id)) this.checkList1.push(m1.id)
            if(m1.children){
              m1.children.forEach(m2=>{
                if(!this.checkList1.includes(m2.id)) this.checkList1.push(m2.id)
                if(m2.children){
                  m2.children.forEach(m3=>{
                    if(!this.checkList1.includes(m3.id)) this.checkList1.push(m3.id)
                    if(m3.children){
                      m3.children.forEach(m4=>{
                        if(!this.checkList1.includes(m4.id)) this.checkList1.push(m4.id)
                      })
                    }
                  })
                }
              })
            }
          })
        }else{
          this.checkList1 = []
        }
      }
      // if (type == 'menu') {
      //   this.$refs.menu.setCheckedNodes(value ? this.menuOptions: []);
      // } else
       if (type == 'dept') {
        this.$refs.dept.setCheckedNodes(value ? this.deptOptions: []);
      }
    },
    // 树权限（父子联动）
    handleCheckedTreeConnect(value, type) {
      if (type == 'menu') {
        this.form.menuCheckStrictly = value ? true: false;
      } else if (type == 'dept') {
        this.form.deptCheckStrictly = value ? true: false;
      }
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.getMenuTreeselect();
      this.getDeptTreeselect()
      this.open = true;
      this.title = "添加角色";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const roleId = row.roleId || this.ids
      const roleMenu = this.getRoleMenuTreeselect(roleId);
      const roleDeptTreeselect = this.getRoleDeptTreeselect(row.roleId);
      getRole(roleId).then(response => {
        this.form = response.data;
        this.open = true;
        this.$nextTick(() => {
          roleMenu.then(res => {
            let checkedKeys = res.checkedKeys
            this.checkList1 = [...checkedKeys]
            // checkedKeys.forEach((v) => {
            //     this.$nextTick(()=>{
            //         this.$refs.menu.setChecked(v, true ,false);
            //     })
            // })
          });
          roleDeptTreeselect.then(res => {
            this.$refs.dept.setCheckedKeys(res.checkedKeys);
          });
        });
        this.title = "修改角色";
      });
    },
    /** 选择角色权限范围触发 */
    dataScopeSelectChange(value) {
      if(value !== '2') {
        this.$refs.dept.setCheckedKeys([]);
      }
    },
    // /** 分配数据权限操作 */
    // handleDataScope(row) {
    //   this.reset();
    //   const roleDeptTreeselect = this.getRoleDeptTreeselect(row.roleId);
    //   getRole(row.roleId).then(response => {
    //     this.form = response.data;
    //     this.openDataScope = true;
    //     this.$nextTick(() => {
    //       roleDeptTreeselect.then(res => {
    //         this.$refs.dept.setCheckedKeys(res.checkedKeys);
    //       });
    //     });
    //     this.title = "分配数据权限";
    //   });
    // },
    // /** 分配用户操作 */
    // handleAuthUser: function(row) {
    //   const roleId = row.roleId;
    //   this.$router.push("/system/role-auth/user/" + roleId);
    // },
    /** 提交按钮 保存所有设置*/
    async submitForm() {
      if(this.form.roleKey&&this.form.roleKey.includes('shop_admin')){
        // 当前角色是管理员
        if(!this.userIds||this.userIds.length==0){
          return this.$alert('管理员角色成员不能为空！')
        }
      }
      this.$refs["form"].validate(async valid => {
        if (valid) {
          this.btnLoading = true
          this.form.menuIds = this.checkList1;
          if (this.form.roleId != undefined) {
            // this.form.menuIds = this.getMenuAllCheckedKeys();
            // this.form.deptIds = this.getDeptAllCheckedKeys();
            // this.form.menuCheckStrictly = false
            try {
              await updateRole(this.form)
              if(this.userList.length){
                await this.saveSelectUser()
              }
              await this.submitDataScope()
              
              this.btnLoading = false
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            } catch (error) {
              this.btnLoading = false
            }

            
          } else {
            // this.form.menuIds = this.getMenuAllCheckedKeys();
            // 生成角色权限字符
            let str = ''
            let pystr = pinyin(this.form.roleName, {
              toneType: "none",
              type: "string",
              heteronym:false
            });
            if(this.userInfo.tenantId){
              str = str+this.userInfo.tenantId+'_'+pystr
            }
            str = str.trim().replace(/\s+/g, '')

            this.form.roleKey = str
            const res =  await addRole(this.form)
            if(res.data.roleId){
              this.form.roleId = res.data.roleId
              if(this.userList.length){
                await this.saveSelectUser()
              }
              await this.submitDataScope()
            }


            this.btnLoading = false
            this.$modal.msgSuccess("新增成功");
            this.open = false;
            this.getList();
          }
        }
      });
    },
    /** 保存数据权限 */
    async submitDataScope() {
      if (this.form.roleId != undefined) {
        this.form.deptIds = this.getDeptAllCheckedKeys();
        await dataScope(this.form)
      }
    },
    
    /** 删除按钮操作 */
    handleDelete(row) {
      const roleIds = row.roleId || this.ids;
      this.$modal.confirm('是否确认删除角色编号为"' + roleIds + '"的数据项？').then(function() {
        return delRole(roleIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },

  }
};
</script>
<style lang="scss" scoped>
.app-container{
  background-color: transparent ;
  padding: 0 !important;
  .search-form-new{
    background-color: transparent;
  }
  .juese-box{
    background-color: #fff;
    padding: 10px;
    border-radius: 10px;
  }
  ::v-deep .table_box{
    padding: 0;
    border-radius: 0;
    box-shadow: none;
  }
  

  .kefu-box{
    margin-top: 8px;
    // background-color: #fff;
    // padding: 10px;
    // border-radius: 10px;
  }

}
.tableheader{
  background-color: #f7f7f7;
  line-height: 36px;
  border: 1px solid #E2E2E2;
  border-bottom: none;
  >div{
    border-right: 1px solid #E2E2E2;
  }
}
.gongneng-box{
  border: 1px solid #E2E2E2;
  border-top: none;
  border-radius: 4px;
  .yiji{
    border-top: 1px solid #E2E2E2;
    // padding:0 10px;
    .name-box{
      padding: 5px 10px;
      flex-shrink: 0;
      width: 150px;
      border-right: 1px solid #E2E2E2;
    }
    .erji-box{
      width: 100%;
      
    }
    .erji{
      
      border-bottom: 1px solid #E2E2E2;
      &:last-of-type{
        border: none;
      }
      
      .name-box{
        width: 150px;

      }
      .sanji-box{
        // border-left: 1px solid #E2E2E2;
        padding-left: 10px;
        padding-top: 5px;
        flex-wrap: wrap;
        .sanji{
          margin-right: 15px;
          margin-bottom: 5px;
        }
      }


      
    }

  }
}
</style>